Skip to content

Android perf metrics: example-app fixes, per-presentation RN host and TTFD hook - #493

Merged
hurali97 merged 6 commits into
callstack:hur/feat/perf-metricsfrom
adrian-callstack:adrian/perf-metrics-android-testing
Oct 15, 2026
Merged

hurali97 merged 6 commits into
callstack:hur/feat/perf-metricsfrom
adrian-callstack:adrian/perf-metrics-android-testing

Conversation

@adrian-callstack

@adrian-callstack adrian-callstack commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on hur/feat/perf-metrics. Testing the Android side of the perf metrics turned up a few fixes, plus changes to the example apps and tests that make TTID/TTFD easier to check. Each commit stands on its own, so reviewing commit by commit is easiest.

Draft: Android e2e passes locally (all suites). iOS e2e could not be verified locally. It hangs the same way on the base branch on this macOS 27 host, while CI's macos-26 runners pass the same suites on main-based branches. It needs a CI run (see Testing).

Commits

  1. fix(bgp): track RN bundle dirs as merge task inputs
    The variant API doesn't treat static source dirs as task inputs. After a JS bundle rebuild, merge<Variant>Assets / package<Variant>Resources stayed UP-TO-DATE and the AAR shipped the previous bundle. This commit registers the generated assets/res dirs, including the expo-updates resources, as inputs.
  2. fix(Expo): respect safe-area insets on the postMessage tab
    Pads the tab with safe-area insets so its content isn't drawn under the system bars when the Expo surface is full screen. ExpoApp56's Jest setup mocks react-native-safe-area-context. This commit comes before 3 on purpose: without it, commit 3 breaks the Android Expo postMessage e2e test, because the bubble ends up under the system bars.
  3. feat(AndroidApp): host React Native in a full-screen ReactNativeActivity
    Moves the RN fragment out of MainActivity's scroll view into a ReactNativeActivity opened from an "Open React Native" button, the same pattern as RNAppScreen on iOS. Every launch is a new presentation, so each one reports its own TTID/TTFD. The Android Detox suites now tap the button instead of scrolling the native shell. Window-focus recovery no longer brings MainActivity to the front while another app activity is resumed.
  4. test(AppleApp): open RN via accessibility id, keep postMessage toast on top
    Adds an accessibility id on the "Open React Native" button, used by the iOS suites. The postMessage toast moves above the NavigationView so it stays visible on the pushed RN screen.
  5. feat(examples): mark TTFD from every example app via a shared hook
    Adds useMarkFullyDisplayed to RNApp, ExpoApp56 and ExpoApp57. DEMO_FULL_DISPLAY_DELAY_MS = 500 stands in for the data a real screen would load first. ExpoApp56 never called markFullyDisplayed, but its Android flavor sets WAIT_FOR_FULL_DISPLAY = true, so it reported no display metrics at all. This commit also fixes the 4 RNApp unit tests that fail on the base branch (route.params is undefined in tests).
  6. test(AndroidApp): tap RN-to-native navigation buttons with sync off
    Fixes intermittent failures in the vanilla settings/referrals tests, which also fail on the base. The tests tapped an RN <Button> with Detox sync on. On Android the press queues ripple view commands, and onPress pushes a native activity straight away. Once the RN host activity pauses, Fabric never mounts those commands, so FabricUIManagerIdlingResources stays busy (View command mount items pending: 1) and the tap times out after ~200 s. The new tapAndWaitForNativeScreen helper taps with sync off and waits for the native screen through UIAutomator, which the tests already used for the assertion.

Testing

Unit / static: run on every commit

base cd34c8e 1–4 5–6
lint / typecheck ✅ ✅ ✅
test:apps: RNApp ❌ 4 failing ❌ same 4 ✅
test:apps: ExpoApp56, shared-tests ✅ ✅ ✅
test:packages ❌ 1 failing ❌ same ❌ same
bgp ktlintCheck ❌ ❌ same ❌ same

These failures are all already on the base branch:

  • packages/cli: strip-framework-binary.test.ts fails with "Calling the test function inside another test function is not allowed".
  • bgp ktlintCheck: fails, and a task that depends on ktlintFormat re-indents ~39 plugin files to 2 spaces. A gradle-plugins/react/brownfield/.editorconfig with 4-space indent fixes it. It's also needed locally, because yarn brownfield:plugin:publish:local runs ktlint. I'll raise it against main separately.

E2E (Detox, local)

Android: Pixel_10_Pro emulator, release APKs. iOS: Xcode 26.6, iPhone 17 Pro on iOS 26.5 (also tried iOS 27), on a macOS 27 host.

Suite base cd34c8e commit 3 (Android) / 4 (AppleApp) tip cd1d0bc
android:expo56 – ✅ 2/2 ✅ 2/2
android:expo57 – ✅ 2/2 ✅ 2/2
android:vanilla ❌ 1/4 (settings)¹ ❌ 1/4 (referrals)¹ ✅ 4/4, 3 runs in a row
ios:expo57 ❌ 0/3² ❌ 0/3² ❌ 0/3²
ios:vanilla / expo56 – ❌ 0/5, 0/3² ❌ 0/5, 0/3²

¹ Intermittent idle timeout in the settings/referrals navigation tests (View command mount items pending: 1), also present on the base. Fixed by commit 6: the fix was verified with one --rebuild and two --test-only runs on the tip, all 4/4, with no busy-app warnings.

² Local environment problem, and the same on the base branch. Two things went wrong:

  1. Fixed locally: the Detox Debug build uses CODE_SIGNING_ALLOWED=NO, so the embedded frameworks (ExpoFont.framework, …) are unsigned. dyld on this machine rejects them at launch (Library not loaded: @rpath/ExpoFont.framework/ExpoFont … code signature). Ad-hoc signing the frameworks and the app after the build (codesign --force --sign -) fixes the crash.
  2. Not fixed: the app then launches and connects to the Detox server, and React Native loads. But the suite's beforeAll (waitForAppleAppReady) never sees the app go idle, so every test hits the 720 s hook timeout. Detox reports this as "can't seem to connect".

The base cd34c8e fails identically (expo57, signed build, iOS 26.5: 0/3, same hook timeout), so this isn't caused by this PR. The likely cause is the host OS: this machine runs macOS 27.0.1, and CI runs macos-26, where the AppleApp vanilla / Expo 57 / Expo 58 e2e jobs passed on main-based branches on 2026-10-13/14. The vanilla/expo56 iOS rows are from earlier, unsigned runs on iOS 27, which failed at launch the same way. iOS needs verifying in CI or on another machine.

Two local-runner issues also came up, neither caused by this PR:

  • scripts/ci-local-androidapp-android-e2e.sh looks for brownfieldlib-…-release.aar, but RNApp's dev/prod flavors (feat: add product flavor and dimension to RN App #386) publish …-devRelease.aar. CI already uses devRelease (.github/actions/androidapp-road-test/action.yml). I worked around it locally with --rebuild.
  • The iOS runner needs a UTF-8 locale (LANG/LC_ALL) for CocoaPods.

To check the metrics by hand: open the RN screen on a Release build and look at the AndroidApp logcat tag. [TTFD] should arrive about 500 ms after [TTID]. jsBundleLoadTime shows as unavailable in Release because the bundle is embedded, which is expected (see PERFORMANCE.md).

Static source directories added through the variant API are not task
inputs, so a rebuilt JS bundle left mergeAssets/packageResources
UP-TO-DATE and the AAR shipped the previous bundle. Register the
generated assets/res dirs (including the expo-updates resources) as
inputs of those tasks.
@adrian-callstack
adrian-callstack force-pushed the adrian/perf-metrics-android-testing branch from fa10188 to f1b0f89 Compare October 14, 2026 19:06
Pad the postMessage tab with the safe-area insets (and the bottom tab
inset) so its content is not drawn under the status bar or tab bar when
the Expo surface is hosted full screen. ExpoApp56's Jest setup mocks
react-native-safe-area-context, since the tests render the tab without a
SafeAreaProvider.
Move the embedded RN fragment out of MainActivity's scroll view into a
dedicated ReactNativeActivity pushed from an "Open React Native" button,
mirroring RNAppScreen on iOS. Each launch creates a new fragment, so
every presentation reports its own TTID/TTFD. The activity now owns the
BrownfieldNavigation delegate.

Detox suites open the RN screen through the new button instead of
scrolling the native shell, and window-focus recovery no longer brings
MainActivity to the front while another app activity is resumed.
…on top

Give the "Open React Native" button an accessibility identifier so the
Detox suites tap it directly instead of matching by text, and move the
postMessage toast above the NavigationView so it stays visible while the
pushed RN screen is in front.
Add a useMarkFullyDisplayed hook to RNApp, ExpoApp56 and ExpoApp57 and
call it from each root (and the Expo Router root). It marks the
presentation fully displayed after DEMO_FULL_DISPLAY_DELAY_MS, which
stands in for the data a real screen would load first.

ExpoApp56 never called markFullyDisplayed even though its Android flavor
waits for full display, so it reported no display metrics at all.
@adrian-callstack
adrian-callstack force-pushed the adrian/perf-metrics-android-testing branch from f1b0f89 to 9236fd7 Compare October 15, 2026 01:01
The vanilla settings/referrals tests tapped an RN <Button> with Detox
synchronization on. The press queues ripple view commands, and onPress
pushes a native activity straight away; once ReactNativeActivity pauses,
Fabric never mounts those commands, so FabricUIManagerIdlingResources
stays busy ("View command mount items pending: 1") and the tap times out
intermittently.

Tap with sync off and wait for the native screen through UIAutomator,
which the tests already did for the assertion.
@adrian-callstack
adrian-callstack marked this pull request as ready for review October 15, 2026 06:45
@hurali97
hurali97 merged commit f1b8fbe into callstack:hur/feat/perf-metrics Oct 15, 2026
hurali97 added a commit that referenced this pull request Oct 16, 2026
* feat: initial impl

* feat: add performance metrics

* fix: expo updates

* feat: add perf metrics to android

* feat: use perf metrics

* Android perf metrics: example-app fixes, per-presentation RN host and TTFD hook (#493)

* fix(bgp): track RN bundle dirs as merge task inputs

Static source directories added through the variant API are not task
inputs, so a rebuilt JS bundle left mergeAssets/packageResources
UP-TO-DATE and the AAR shipped the previous bundle. Register the
generated assets/res dirs (including the expo-updates resources) as
inputs of those tasks.

* fix(Expo): respect safe-area insets on the postMessage tab

Pad the postMessage tab with the safe-area insets (and the bottom tab
inset) so its content is not drawn under the status bar or tab bar when
the Expo surface is hosted full screen. ExpoApp56's Jest setup mocks
react-native-safe-area-context, since the tests render the tab without a
SafeAreaProvider.

* feat(AndroidApp): host React Native in a full-screen ReactNativeActivity

Move the embedded RN fragment out of MainActivity's scroll view into a
dedicated ReactNativeActivity pushed from an "Open React Native" button,
mirroring RNAppScreen on iOS. Each launch creates a new fragment, so
every presentation reports its own TTID/TTFD. The activity now owns the
BrownfieldNavigation delegate.

Detox suites open the RN screen through the new button instead of
scrolling the native shell, and window-focus recovery no longer brings
MainActivity to the front while another app activity is resumed.

* test(AppleApp): open RN via accessibility id, keep postMessage toast on top

Give the "Open React Native" button an accessibility identifier so the
Detox suites tap it directly instead of matching by text, and move the
postMessage toast above the NavigationView so it stays visible while the
pushed RN screen is in front.

* feat(examples): mark TTFD from every example app via a shared hook

Add a useMarkFullyDisplayed hook to RNApp, ExpoApp56 and ExpoApp57 and
call it from each root (and the Expo Router root). It marks the
presentation fully displayed after DEMO_FULL_DISPLAY_DELAY_MS, which
stands in for the data a real screen would load first.

ExpoApp56 never called markFullyDisplayed even though its Android flavor
waits for full display, so it reported no display metrics at all.

* test(AndroidApp): tap RN-to-native navigation buttons with sync off

The vanilla settings/referrals tests tapped an RN <Button> with Detox
synchronization on. The press queues ripple view commands, and onPress
pushes a native activity straight away; once ReactNativeActivity pauses,
Fabric never mounts those commands, so FabricUIManagerIdlingResources
stays busy ("View command mount items pending: 1") and the tap times out
intermittently.

Tap with sync off and wait for the native screen through UIAutomator,
which the tests already did for the assertion.

* refactor: use generated source dir

* docs: move performance metrics guide to the docs website

Add a Performance Metrics guide covering startup timings, TTID, TTFD,
JS FPS and UI FPS. Document markFullyDisplayed in the JavaScript API
reference and remove PERFORMANCE.md.

* test: stub RN bundle tasks with output dirs in Gradle plugin fixtures

The plugin wires createBundle<Variant>JsAndAssets jsBundleDir/resourcesDir
outputs as generated sources and fails fast without them, so plain
tasks.register stubs broke the AGP compatibility matrix.

* fix(ios): forget earlier bundle timings when a JS bundle load fails

A failed reload left didLoadBundle and latestTimings from the previous
load, so a new onBundleLoaded registration got stale timings right away.

* chore(ios): restore RNApp Podfile.lock after a bad merge

The merge duplicated the boost, BrownfieldNavigation and React-bridging
entries, which made pod install crash.

* fix: pass brownfieldPresentationID only to measured presentations

Views, view controllers and fragments created without the metrics APIs
now keep their initial props as is and create no display session, on
both iOS and Android.

* fix(ios): start initial display only after the React Native root exists

With Expo Updates, view() returns a placeholder and inserts the root
later. The appearance probe sat in the placeholder, so initial display
could complete before the root existed, or when its creation failed.
The probe now goes into the real root, and the view controller reports
appearance only after that.

* test(e2e): keep Detox sync off on the AppleApp native shell

AppleApp preloads the JS bundle at launch, and the RN view now sits
behind the Open React Native button. DetoxSync keeps the app busy on
React Native (bundle load) until RN content appears, so re-enabling
sync on the native shell made the app never go idle and every iOS
test timed out. Sync is turned back on by openReactNative once the RN
screen is visible.

* test(e2e): open the AppleApp RN screen with a coordinate tap

Detox's element tap injects a synthesized touch at the accessibility
activation point, which SwiftUI's NavigationLink ignores: the tap was
reported as successful, but the RN screen was never pushed. Tap the
center of the Open React Native button through XCUITest (device.tap)
instead, which delivers a real touch.

---------

Co-authored-by: Adrian <138571007+adrian-callstack@users.noreply.github.com>
Co-authored-by: Adrian Buciuman <adrian.buciuman@callstack.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants